﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.IO;

namespace WsTestClient
{
    class Program
    {
        static void Main(string[] args)
        {
            //Sample data is from here
            //http://ru.wikipedia.org/wiki/WebSocket

            TcpClient client = new TcpClient("localhost", 8181);
            //TcpClient client = new TcpClient("websockets.org", 8787);
            NetworkStream stream = client.GetStream();
            using (StreamReader reader = new StreamReader(stream))
            using (StreamWriter writer = new StreamWriter(stream))
            {
                writer.WriteLine("GET /websock HTTP/1.1");
                writer.WriteLine("Upgrade: WebSocket");
                writer.WriteLine("Connection: Upgrade");

                //writer.WriteLine("Sec-WebSocket-Key2: 4 @1  46546xW%0l 1 5");
                writer.WriteLine("Sec-WebSocket-Key2: 1_ tx7X d  <  nw  334J702) 7]o}` 0");
                writer.WriteLine("Host: example.com");
                //writer.WriteLine("Sec-WebSocket-Key1: 12998 5 Y3 1  .P00");
                writer.WriteLine("Sec-WebSocket-Key1: 18x 6]8vM;54 *(5:  {   U1]8  z [  8");
                writer.WriteLine("Origin: http://example.com");

                writer.WriteLine("WebSocket-Protocol: sample");
                writer.WriteLine("");
                //writer.Write("^n:ds[4U");
                writer.Write("Tm[K T2u");
            }
        }
    }
}
